package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.ProCategoryBean;
import com.xoms.admin.model.vo.ProCategoryVo;
import com.xoms.admin.model.vo.TreeNodeBean;
import com.xoms.admin.persist.dao.ProCategoryDao;

@Repository
public class ProCategoryImpl extends BaseImpl implements ProCategoryDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProCategoryMapper";

	@Override
	public ProCategoryBean selectOneByName(String name) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByName", name);
	}

	@Override
	public int insert(ProCategoryBean data) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", data);
	}

	@Override
	public int update(ProCategoryBean data) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", data);
	}

	@Override
	public ProCategoryBean selectOneById(String cid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", cid);
	}

	@Override
	public int selectCount2Category(String cid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount2Category", cid);
	}

	@Override
	public int del(String cid) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delete", cid);
	}

	@Override
	public List<ProCategoryVo> selectAllCates() {
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectAllCates");
	}

	@Override
	public List<TreeNodeBean> selectCategores() {
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectCategores");
	}
	
	@Override
	public List<ProCategoryVo> selectHqCates() {
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectHqCates");
	}

	@Override
	public List<TreeNodeBean> selectHqCateTrees(Integer type) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (type != null) {
			params.put("type", type);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectHqCateTrees", params);
	}

	@Override
	public List<TreeNodeBean> selectHqFirstCateTrees() {
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectHqFirstCateTrees");
	}

	@Override
	public Integer selectMaxSort(String parentId) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectMaxSort", parentId);
	}

	@Override
	public List<TreeNodeBean> selectCategoresByPid(List<TreeNodeBean> cates) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (cates != null) {
			params.put("list", cates);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectCategoresByPid", params);
	}

	@Override
	public int updateSorts(List<String> sortList) {
		Map<String, Object> params = new HashMap<>();
		params.put("sorts", sortList);

		return sqlSessionTemplate.update(NAME_SPACE + ".updateSorts", params);
	}

}
